/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package client;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Grubi
 */
public class TableModel extends javax.swing.table.AbstractTableModel{
    List<User> lst = new ArrayList<>();

    @Override
    public int getRowCount() {
        return 13;
    }

    @Override
    public int getColumnCount() {
        return lst.size()+1;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        //erste Spalte returnieren
        return lst.get(columnIndex).getIndexObject(rowIndex);
    }

    @Override
    public String getColumnName(int column) {
        try{
            return (String) lst.get(column).getName();
        }catch(IndexOutOfBoundsException ex){
            return "Spieler " + column;
        }
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        lst.get(columnIndex-1).set(rowIndex, (int) aValue);
        fireTableCellUpdated(rowIndex, columnIndex);
    }

    void addUser(User u) {
        lst.add(u);
    }
    
}
